'''
Created on Aug 20, 2019

@author: yc
'''
from . import world as w
from django.http import HttpResponse
import json

#------------------------对外接口----------------------------------
#启动world
world = w.World()

#接口1: 返回窗口信息
def windowInfo(request):
    res = {}
    res["space_width"] = w.Space.SPACE_WIDTH * w.Space.BASESIZE
    res["space_height"] = w.Space.SPACE_HEIGHT * w.Space.BASESIZE
    return HttpResponse(json.dumps(res))

#接口2: 返回迷宫数组
def mazeInfo(request):
    maze = world.getMaze()
#     res = {}
#     res["mazeArray"] = maze.getRealLineArray()
    return HttpResponse(json.dumps(maze.getRealLineArray()))

#接口3: 返回车位置
def carInfo(request):
    car = world.getCar()
    res = {}
    res["location"] = car.getRealLocation()
    res["direction"] = car.direction
    return HttpResponse(json.dumps(res))
    
#接口4: 返回整个二维世界矩阵
def worldMatrix(request):
    res = {}
#     res["mazeArray"] = ','.join(w.Space.WORLD_MATRIX)
    return HttpResponse(w.Space.WORLD_MATRIX)

